package org.example.musicserver.controller;

import jakarta.annotation.Resource;
import org.example.musicserver.common.Result;
import org.example.musicserver.entity.ListSong;
import org.example.musicserver.entity.Song;
import org.example.musicserver.service.ListSongService;
import org.example.musicserver.service.SongService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ListSongController {
    @Resource
    private ListSongService listSongService;
    @Resource
    private SongService songService;
    // 返回歌单里指定歌单ID的歌曲信息
    @GetMapping("/listSong/detail")
    public Result listSongOfSongId(@RequestParam int playListId) {
        List<ListSong> listsong = listSongService.listSongOfSongId(playListId);
        // 定义一个新的列表来存储查询到的 Song 详情
        List<Song> songDetails = new ArrayList<>();
        // 遍历 listsong 列表
        for (ListSong listdetail : listsong) {
            // 假设 getSongDetailsById 方法接受一个 songId 并返回与之关联的 Song 对象的详细信息
            Song songDetail = (Song) songService.songOfId(listdetail.getSongId()).getData();
            // 将 Song 对象添加到 songDetails 列表中
            songDetails.add(songDetail);
        }
        // 将结果封装到 Result 对象中并返回
        return Result.success("返回结果成功",songDetails); // 假设 Result 是一个用于封装响应数据的类
    }
}
